﻿namespace WordCloudClient.ViewModels
{
    public class ViewFilterWordsViewModel : DataGridCommonVM
    {
        public DelegateCommand ExecuteUpdateIsEnableDelegateCommand { get; private set; }
        public ViewFilterWordsViewModel(SystemService systemService, WinEditHelper winEditHelper) : base(systemService, winEditHelper)
        {
            EditWinAddress = "WinEditFilter";
            ExecuteUpdateIsEnableDelegateCommand = new DelegateCommand(ExecuteUpdateIsEnable);
        }
        public override void BindData()
        {
            List<FilterWordsEntity> listEntity = _systemService.GetFilterWordsEntities(QueryModel, ref TotalPages, ref TotalCount);
            ObjectEntities = new ObservableCollection<object>(listEntity);
            PaginationModel = ControlHelper.GetPaginationModel(QueryModel.PageIndex, QueryModel.PageSize, TotalPages, TotalCount);
        }
        public void ExecuteUpdateIsEnable()
        {
            FilterWordsEntity FilterWordsEntity = (FilterWordsEntity)SelectObject;
            FilterWordsEntity.IsEnable = FilterWordsEntity.IsEnable == 1 ? 0 : 1;
            string errorMsg = string.Empty;
            _systemService.UpdateFilterWord(FilterWordsEntity, ref errorMsg);
        }
        public override void ExecuteDelete()
        {
            FilterWordsEntity FilterWordsEntity = (FilterWordsEntity)SelectObject;
            if (string.IsNullOrEmpty(FilterWordsEntity.Word))
            {
                MessageTips.InfoMessage("请选择一条数据");
                return;
            }
            if (MessageTips.AccentMessage($"是否删除{FilterWordsEntity.Word}？") == MessageBoxResult.Yes)
            {
                if (_systemService.DeleteFilterWord(FilterWordsEntity))
                {
                    MessageTips.SuccessMessage("删除成功！");
                    BindData();
                }
            }
        }
    }
}
